--[[

	qLoc by Quel
	Displays your coordinates
	11/15/06 v1.0

--]]

local timeslice = 0;

--**********************************************************
function LocFrame_OnLoad()
	LocFrame:Show();
	KeyTable = {
		{"Mount","ITEM Stormpike Battle Charger"},
		{"Shoot","SPELL Shoot"},
	};
	timeslice = 0;
end

--**********************************************************
function LocMapFrame_OnLoad()
	LocMapFrame:Show();
	timeslice = 0;
end

--**********************************************************
function LocFrame_OnUpdate(arg1)
	if (timeslice > .100) then
		local lx, ly = GetPlayerMapPosition("player");
		--LocText:SetText(floor(lx *100) .. "," .. floor (ly * 100));
		LocText:SetText(string.format("%.1f,%.1f", lx *100, ly * 100));
		timeslice = 0;
	else
		timeslice = timeslice + arg1;
	end
end

--**********************************************************
function LocMapFrame_OnUpdate(arg1)
	if (timeslice > .100) then
		-- show coords under the mouse
		local mousex, mousey = GetCursorPosition();

		-- The logic to convert the screen-wide mouse coordinates to map coordinates based on
		-- Xavier's design in the Loc add-on.

		local scale = WorldMapFrame:GetScale();

		mousex = mousex / scale;
		mousey = mousey / scale;
	
		local width = WorldMapButton:GetWidth();
		local height = WorldMapButton:GetHeight();
		local centerX, centerY = WorldMapFrame:GetCenter();
	
		if (not centerX) then
			centerX = width / 2;
		end
	
		if (not centerY) then
			centerY = height / 2;
		end
	
		local adjustedX = (mousex - (centerX - (width/2))) / width;
		local adjustedY = ((centerY + (height/2) - mousey) / height) - 0.02;

		LocMapText:SetText(string.format("Mouse: %.1f,%.1f", adjustedX * 100.0, adjustedY * 100.0));

		px, py = GetPlayerMapPosition("player");
		LocMapText2:SetText(string.format("You: %.1f,%.1f", px * 100, py * 100));

		timeslice = 0;
	else
		timeslice = timeslice + arg1;
	end
end

--**********************************************************
local lBeingDragged;
function LocFrame_OnDragStart()
	LocFrame:StartMoving();
	lBeingDragged = 1;
end

function LocFrame_OnDragStop()
	LocFrame:StopMovingOrSizing();
	lbeingDragged = 0;
end
